/**
 * Copyright (c) 2020 铭软科技(mingsoft.net)
 * 本软件及相关文档文件（以下简称“软件”）的版权归 铭软科技 所有
 * 遵循铭软科技《保密协议》
 */
package net.mingsoft.mwebsite.interceptor;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import net.mingsoft.basic.biz.IAppBiz;
import net.mingsoft.basic.constant.Const;
import net.mingsoft.basic.entity.AppEntity;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.basic.util.SpringUtil;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * AppId拦截器，提供给站群使用
 */
public class AppInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        IAppBiz websiteBiz = (IAppBiz) SpringUtil.getBean(IAppBiz.class);
        // 获取用户所请求的域名地址
        AppEntity appEntity = websiteBiz.getOne(Wrappers.<AppEntity>lambdaQuery().like(AppEntity::getAppUrl, BasicUtil.getDomain()),false);
        BasicUtil.setSession(Const.APP,appEntity);
        return super.preHandle(request, response, handler);
    }
}
